View.h++ Sample Code

This page provides two simple examples of View.h++ code. From here you can also access:

C/Motif versus C++/View.h++

Example using C with Motif

XmString  delMsg,  button1,  filename:
delMsg = XmStringCreateSimple ("Delete");
filename = XmStringCreateSimple ("workfile");
button1 = XmStringConcat (delMsg, filename);

Example using C++ with View.h++

RWXmString delMsg ("Delete"), filename ("workfile"), button1;
button1 = delMsg + filename;  // Using + to concatenate

Hello World Example

The legendary "Hello World" example, done with View.h++

class DemoView  :  public RWMainView  
public:
DemoView (unsigned argc, char* argv [ ] )  :  RWMainView (argc, argv)
{ RW Menu *menu = new RWMenu;
menu->addOption ("Go", 'G', this, RWMethod (&DemoView::sayHello));
menu->addSeparator ( );
menu->addOption ("Quit", 'Q', this RWMethod (&DemoView::shutdown));
menu->attachTo (*menuBar, "File", 'F');
}
protected:
void  sayHello ( )  { writeTextAt ("Hello World!", 100, 30); }
void  shutdown ( )  { exit  (0);  }
};
int main (unsigned argc, char* argv [ ] )
{
DemoView view (argc, argv);
view.start ( );
return 0;
}

© Copyright 1995, Rogue Wave Software, Inc.